package com.winterwar.dao.hibernate;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.winterwar.base.RegisteredEvent;
import com.winterwar.dao.RegisteredEventDAO;

public class RegisteredEventDAOHibernate extends HibernateDaoSupport implements RegisteredEventDAO{
	private Log log = LogFactory.getLog(RegisteredEventDAO.class);
	public RegisteredEvent get(Integer regEventID) {
		return (RegisteredEvent) getHibernateTemplate().get(RegisteredEvent.class, regEventID);
	}

	public List getAll() {
		return getHibernateTemplate().find("from RegisteredEvent");
	}

	public void remove(Integer regEventID) {
		Object event = getHibernateTemplate().load(RegisteredEvent.class, regEventID);
		getHibernateTemplate().delete(event);
		getHibernateTemplate().flush();
		getHibernateTemplate().clear();
	}

	public void save(RegisteredEvent event) {
		getHibernateTemplate().saveOrUpdate(event);
		getHibernateTemplate().flush();
		getHibernateTemplate().clear();
		if(log.isDebugEnabled()){
			log.debug("Registered Event ID set to: " + event.getRegEventID());
		}
	}
	public List getByRegistration(Integer registrationID){
		return getHibernateTemplate().find("from RegisteredEvent where RegID = " + registrationID);
	}

}
